package com.huawei.esdk.tp.device.smc.v100r003c10;

import java.util.List;

import com.huawei.esdk.platform.common.SDKErrorCode;
import com.huawei.esdk.platform.common.SDKResult;
import com.huawei.esdk.platform.commu.itf.ICXFSOAPProtocolAdapter;
import com.huawei.esdk.platform.exception.ProtocolAdapterException;
import com.huawei.esdk.tp.device.smc.v100r003c00.SMC20V1R3C00SiteManagerCapabilityImpl;
import com.huawei.esdk.tp.device.smc.v100r003c10.convert.TPSMC20V1R3C10SiteMgrConvert;
import com.huawei.esdk.tp.domain.model.Site;
import com.huawei.esdk.tp.domain.model.bean.PagedList;
import com.huawei.esdk.tp.domain.model.bean.QuerySites;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.AddSite;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.AddSiteResponse;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.ArrayOfString;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.DeleteSites;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.DeleteSitesResponse;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.EditSite;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.EditSiteResponse;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.QuerySitesResponse;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.SmcExternal2Soap;

public class SMC20V1R3C10SiteManagerCapabilityImpl extends SMC20V1R3C00SiteManagerCapabilityImpl implements
    SMC20V1R3C10ISiteManagerCapability
{
    private TPSMC20V1R3C10SiteMgrConvert tpSiteMgrConvertService = new TPSMC20V1R3C10SiteMgrConvert();
    
    /** * @param cxfSoapProtocolAdapter */
    public SMC20V1R3C10SiteManagerCapabilityImpl(ICXFSOAPProtocolAdapter cxfSOAPProtocolAdapter)
    {
        super(cxfSOAPProtocolAdapter);
    }
    
    protected String getR3C10SouthItfName()
    {
        return SmcExternal2Soap.class.getName();
    }
    
    @Override
    public SDKErrorCode addSiteInfoEx(Site sitesInfo)
    {
        SDKErrorCode result = new SDKErrorCode();
        
        AddSiteResponse response = null;
        
        // 调用接口前转换
        AddSite resMsg = tpSiteMgrConvertService.addSiteInfoModel2Soap(sitesInfo);
        
        try
        {
            response = (AddSiteResponse)sendProtocolMessage(resMsg, getR3C10SouthItfName(), "addSite");
        }
        catch (ProtocolAdapterException e)
        {
            result.setErrCode(e.getErrorCode());
            return result;
        }
        
        result.setErrCode(response.getAddSiteResult().getErrCode());
        
        return result;
    }
    
    @Override
    public SDKErrorCode editSiteInfoEx(Site sitesInfo)
    {
        SDKErrorCode result = new SDKErrorCode();
        
        EditSiteResponse response = null;
        
        // 调用接口前转换
        EditSite resMsg = tpSiteMgrConvertService.editSiteInfoModel2Soap(sitesInfo);
        
        try
        {
            response = (EditSiteResponse)sendProtocolMessage(resMsg, getR3C10SouthItfName(), "editSite");
        }
        catch (ProtocolAdapterException e)
        {
            result.setErrCode(e.getErrorCode());
            return result;
        }
        
        result.setErrCode(response.getEditSiteResult().getErrCode());
        
        return result;
    }
    
    @Override
    public SDKErrorCode deleteSiteInfo(List<String> uris)
    {
        SDKErrorCode result = new SDKErrorCode();
        DeleteSitesResponse responseSouth = null;
        try
        {
            DeleteSites resMsg = new DeleteSites();
            ArrayOfString strArray = new ArrayOfString();
            strArray.getString().addAll(uris);
            resMsg.setSites(strArray);
            responseSouth = (DeleteSitesResponse)sendProtocolMessage(resMsg, getR3C10SouthItfName(), "deleteSites");
            result.setErrCode(responseSouth.getDeleteSitesResult().getErrCode());
        }
        catch (ProtocolAdapterException e)
        {
            result.setErrCode(e.getErrorCode());
            return result;
        }
        return result;
    }
    
    /**
     * * 查询会场信息
     * @param query 领域bean
     * @return SDKResult 公用返回值
     */
    @Override
    public SDKResult<PagedList<Site>> querySites(QuerySites query)
    {
        com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.QuerySites south =
            tpSiteMgrConvertService.querySitesModal2Soap(query);
        QuerySitesResponse southResponse = null;
        SDKResult<PagedList<Site>> result = new SDKResult<PagedList<Site>>();
        try
        {
            southResponse = (QuerySitesResponse)sendProtocolMessage(south, getR3C10SouthItfName(), "querySites");
            result = tpSiteMgrConvertService.querySitesSoap2Modal(southResponse);
        }
        catch (ProtocolAdapterException e)
        {
            result.setErrCode(e.getErrorCode());
            return result;
        }
        
        return result;
    }
}
